﻿using System;
using System.Reflection;

namespace CloudStorageProvider
{
    public class StorageProviderFactory
    {
        /// <summary>
        /// Returns an instance of an IStorageProvider object by it's name.
        /// </summary>
        /// <param name="providerName">The name of the IStorageProvider class to create.</param>
        /// <returns>IStorageObject of type [providerName].</returns>
        public static IStorageProvider GetProvider(string providerName)
        {
            Type t;

            // Get the executing assembly name
            Assembly a = Assembly.Load(Assembly.GetExecutingAssembly().GetName().Name);

            // Find a provider which matches the string name provided and create an instance of it
            object c = a.CreateInstance(providerName);
            t = c.GetType();

            return (IStorageProvider) c;
        }
    }
}